/*     */ package com.wgcloud.controller;
/*     */ 
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import com.wgcloud.entity.Equipment;
/*     */ import com.wgcloud.service.EquipmentService;
/*     */ import com.wgcloud.service.LogInfoService;
/*     */ import com.wgcloud.util.PageUtil;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/equipment"})
/*     */ public class EquipmentController
/*     */ {
/*  35 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.EquipmentController.class);
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private EquipmentService equipmentService;
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private LogInfoService logInfoService;
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"list"})
/*     */   public String EquipmentList(Equipment equipment, Model model) {
/*  54 */     Map<String, Object> params = new HashMap<>();
/*     */     try {
/*  56 */       StringBuffer url = new StringBuffer();
/*  57 */       String hostname = null;
/*  58 */       if (!StringUtils.isEmpty(equipment.getName())) {
/*  59 */         hostname = equipment.getName();
/*  60 */         params.put("name", hostname.trim());
/*  61 */         url.append("&name=").append(hostname);
/*     */       } 
/*  63 */       PageInfo pageInfo = this.equipmentService.selectByParams(params, equipment.getPage().intValue(), equipment.getPageSize().intValue());
/*  64 */       PageUtil.initPageNumber(pageInfo, model);
/*  65 */       model.addAttribute("pageUrl", "/equipment/list?1=1" + url.toString());
/*  66 */       model.addAttribute("page", pageInfo);
/*  67 */       model.addAttribute("equipment", equipment);
/*  68 */     } catch (Exception e) {
/*  69 */       logger.error("查询资产信息错误", e);
/*  70 */       this.logInfoService.save("查询资产信息错误", e.toString(), "1");
/*     */     } 
/*     */     
/*  73 */     return "equipment/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"save"})
/*     */   public String saveEquipment(Equipment equipment, Model model, HttpServletRequest request) {
/*     */     try {
/*  88 */       if (StringUtils.isEmpty(equipment.getId())) {
/*  89 */         this.equipmentService.save(equipment);
/*     */       } else {
/*  91 */         this.equipmentService.updateById(equipment);
/*     */       } 
/*  93 */     } catch (Exception e) {
/*  94 */       logger.error("保存资产错误", e);
/*  95 */       this.logInfoService.save("保存资产错误", e.toString(), "1");
/*     */     } 
/*  97 */     return "redirect:/equipment/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"edit"})
/*     */   public String edit(Model model, HttpServletRequest request) {
/* 109 */     String errorMsg = "添加资产";
/* 110 */     String id = request.getParameter("id");
/* 111 */     Equipment Equipment = new Equipment();
/*     */     try {
/* 113 */       if (StringUtils.isEmpty(id)) {
/* 114 */         model.addAttribute("equipment", Equipment);
/* 115 */         return "equipment/add";
/*     */       } 
/* 117 */       Equipment = this.equipmentService.selectById(id);
/* 118 */       model.addAttribute("equipment", Equipment);
/* 119 */     } catch (Exception e) {
/* 120 */       logger.error(errorMsg, e);
/* 121 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 123 */     return "equipment/add";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"view"})
/*     */   public String viewChart(Model model, HttpServletRequest request) {
/* 136 */     String errorMsg = "查看资产信息错误";
/* 137 */     String id = request.getParameter("id");
/* 138 */     Equipment Equipment = new Equipment();
/*     */     try {
/* 140 */       Equipment = this.equipmentService.selectById(id);
/* 141 */       model.addAttribute("equipment", Equipment);
/* 142 */     } catch (Exception e) {
/* 143 */       logger.error(errorMsg, e);
/* 144 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 146 */     return "equipment/view";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"del"})
/*     */   public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
/* 161 */     String errorMsg = "删除资产信息错误";
/* 162 */     Equipment Equipment = new Equipment();
/*     */     try {
/* 164 */       if (!StringUtils.isEmpty(request.getParameter("id"))) {
/* 165 */         String[] ids = request.getParameter("id").split(",");
/* 166 */         for (String id : ids) {
/* 167 */           Equipment = this.equipmentService.selectById(id);
/* 168 */           this.logInfoService.save("删除资产信息：" + Equipment.getName(), "删除资产信息：" + Equipment.getName(), "0");
/*     */         } 
/* 170 */         this.equipmentService.deleteById(ids);
/*     */       } 
/* 172 */     } catch (Exception e) {
/* 173 */       logger.error(errorMsg, e);
/* 174 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 176 */     return "redirect:/equipment/list";
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/EquipmentController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */